/**
 * 
 */
package org.h2.index;

import java.sql.SQLException;

import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.table.Column;
import org.h2.table.TableExtern;
import org.h2.table.TableExternAdapter;
import org.h2.value.Value;

/**
 * @author falario
 *
 */
public class ExternIndex extends Index {
	
	private TableExternAdapter delegated=null;

	/**
	 * @param table
	 * @param id
	 * @param name
	 * @param columns
	 * @param indexType
	 */
	public ExternIndex(TableExtern table, TableExternAdapter delegated, int id, String name, Column[] columns,
			IndexType indexType) {
		super(table, id, name, columns, indexType);
		// TODO Auto-generated constructor stub
		this.delegated=delegated;
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#close(org.h2.engine.Session)
	 */
	public void close(Session session) throws SQLException {
		// TODO Auto-generated method stub
		this.delegated.closeSource();
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#add(org.h2.engine.Session, org.h2.result.Row)
	 */
	public void add(Session session, Row row) throws SQLException {
		// TODO Auto-generated method stub
		this.delegated.insertData(session, row);
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#remove(org.h2.engine.Session, org.h2.result.Row)
	 */
	public void remove(Session session, Row row) throws SQLException {
		// TODO Auto-generated method stub
		this.delegated.removeData(session, row);
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#find(org.h2.engine.Session, org.h2.result.SearchRow, org.h2.result.SearchRow)
	 */
	public Cursor find(Session session, SearchRow first, SearchRow last)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.delegated.getData(session, first, last);
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#getCost(int[])
	 */
	public int getCost(int[] masks) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#remove(org.h2.engine.Session)
	 */
	public void remove(Session session) throws SQLException {
		// TODO Auto-generated method stub
		//nothing to do
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#truncate(org.h2.engine.Session)
	 */
	public void truncate(Session session) throws SQLException {
		// TODO Auto-generated method stub
		//nothing to do
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#canGetFirstOrLast(boolean)
	 */
	public boolean canGetFirstOrLast(boolean first) {
		// TODO Auto-generated method stub
		return this.delegated.canGetFirstOrLast();
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#findFirstOrLast(org.h2.engine.Session, boolean)
	 */
	public Value findFirstOrLast(Session session, boolean first)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.delegated.findFirstOrLast(session, first);
	}

	/* (non-Javadoc)
	 * @see org.h2.index.Index#needRebuild()
	 */
	public boolean needRebuild() {
		// TODO Auto-generated method stub
		return this.delegated.needRebuild();
	}

	/* (non-Javadoc)
	 * @see org.h2.engine.DbObject#checkRename()
	 */
	public void checkRename() throws SQLException {
		// TODO Auto-generated method stub
		throw Message.getUnsupportedException();
	}
}